package com.yeyks.controller;

import com.yeyks.common.base.Arguments;
import com.yeyks.common.utils.excel.ExcelUtil;
import com.yeyks.search.pojo.result.hotel.ExportHotelResult;
import com.yeyks.search.pojo.result.hotel.ExportHotelRoomResult;
import com.yeyks.search.service.hotel.EsExportHotelService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Es的 酒店相关数据导出
 *
 * @author: shuai
 * @date: 2019/10/21 0021 11:25
 */
@RestController
@RequestMapping("/export")
public class EsExportHotelController {


    @Autowired
    private EsExportHotelService esExportHotelService;

    @ApiOperation("导出某个城市的酒店信息")
    @GetMapping("/hotel")
    public void esExportHotel(HttpServletResponse response,
                              @RequestParam(value = "addressName", defaultValue = "杭州") String addressName) {
        List<ExportHotelResult> exportHotelResults = esExportHotelService.getHotelListResultInCnBooking(addressName);
        ExcelUtil.disposeWriteExcelWithSheets(response, exportHotelResults, new ExportHotelResult());
    }

    @ApiOperation("导出某个城市的所有酒店房态")
    @GetMapping("/hotel/room")
    public void esExportHotelRoom(HttpServletResponse response,
                                  @RequestParam(value = "cityName") String cityName) {
        Arguments.strIsNull(cityName, "城市名称不能为空");
        List<ExportHotelRoomResult> hotelRoomListResultInCnBooking = esExportHotelService.getHotelRoomListResultInCnBooking(cityName);
        ExcelUtil.disposeWriteExcelWithSheets(response, hotelRoomListResultInCnBooking, new ExportHotelRoomResult());
    }

}
